package skipass;

import skipass.command.CommandChain;
import skipass.command.CommandChainFactory;
import skipass.container.Card;


public class TurnStile {

	CommandChainFactory commandChainFactory;
	CardStatSystem stat;	

	public TurnStile(CardStatSystem stat) {
		this.stat = stat;
		commandChainFactory = CommandChainFactory.getInstance(stat);
	}

	public boolean checkCard(Card card) {	
		if(stat.isOpen()) {
			CommandChain commandChain = commandChainFactory.createCommandChain(card);
			boolean isAccepted = commandChain.executeChain();		
			stat.writeStat(card.getType(), isAccepted);
			return isAccepted;
		} else return false;
	}

}